import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'
import config from './src/config/config'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    port: 8080,
    fs: {
      // 允许访问上层目录
      allow: ['..']
    },
    proxy: {
      '/api': {
        target: config.getServerUrl(),
        changeOrigin: true,
        secure: false
      }
    }
  },
  worker: {
    format: 'es'
  },
  optimizeDeps: {
    include: ['pdfjs-dist'],
    esbuildOptions: {
      // 在预构建时保留 jsmind 的 CommonJS 格式
      preserveSymlinks: true
    }
  },
  build: {
    commonjsOptions: {
      // 确保 CommonJS 模块能够正确处理
      transformMixedEsModules: true,
      include: [/jsmind/]
    },
    rollupOptions: {
      output: {
        manualChunks: {
          'pdfjs': ['pdfjs-dist']
        }
      }
    }
  }
}) 